import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/widgets/button/normal_button.dart';
import 'package:finance_app/src/widgets/form/text_area_input_form.dart';
import 'package:flutter/material.dart';

import 'default_bottom_sheet.dart';

///调整库存
showRejectLeaveRequestInputBottomSheet(BuildContext context,
        {ValueChanged<String> onDone}) =>
    showDefaultBottomSheet(context,
        child: _RejectExpenseInputWidget(
          onClick: onDone,
          title: S.current.reason_optional,
          btnText: S.current.reject,
        ),
        isScrollControlled: true,
        title: S.current.reject_leave_request);

///调整库存
showAdjustInventoryInputBottomSheet(BuildContext context,
        {ValueChanged<String> onDone}) =>
    showDefaultBottomSheet(context,
        child: _RejectExpenseInputWidget(
          onClick: onDone,
          title: S.current.additional_notes_optional,
          btnText: S.current.done,
        ),
        isScrollControlled: true,
        title: S.current.adjust_inventory);

/// reject expense input
showRejectExpenseInputBottomSheet(BuildContext context,
        {ValueChanged<String> onReject}) =>
    showDefaultBottomSheet(context,
        child: _RejectExpenseInputWidget(
          onClick: onReject,
          title: S.current.reason_optional,
          btnText: S.current.reject,
        ),
        isScrollControlled: true,
        title: S.current.reject_expense_claim);

class _RejectExpenseInputWidget extends StatefulWidget {
  final ValueChanged<String> onClick;
  final String title;
  final String btnText;

  const _RejectExpenseInputWidget(
      {Key key, this.onClick, this.title, this.btnText})
      : super(key: key);

  @override
  __RejectExpenseInputWidgetState createState() =>
      __RejectExpenseInputWidgetState();
}

class __RejectExpenseInputWidgetState extends State<_RejectExpenseInputWidget> {
  TextEditingController reasonController = TextEditingController();
  FocusNode reasonFocusNode = FocusNode();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    reasonController.dispose();
    reasonFocusNode.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        TextAreaInputForm(
          controller: reasonController,
          focusNode: reasonFocusNode,
          title: widget.title,
        ),
        SizedBox(
          height: getDp(30),
        ),
        NormalButton(
          onTap: () => widget.onClick(reasonController.text),
          title: widget.btnText,
        ),
      ],
    );
  }
}
